﻿@using System.Linq
@using Abp.Extensions
@using Abp.Json
@using Magicodes.Admin.Web.Areas.Admin.Models.Common
@model FeatureTreeItemModel
@{
    var features = Model.EditModel.Features.Where(p => p.ParentName == Model.ParentName || (p.ParentName.IsNullOrEmpty() && Model.ParentName.IsNullOrEmpty())).ToList();
    if (features.Any())
    {
        <ul>
            @foreach (var feature in features)
                {
                    var featureValue = Model.EditModel.FeatureValues.FirstOrDefault(fv => fv.Name == feature.Name);
                    var value = featureValue == null ? feature.DefaultValue : featureValue.Value;
                    var isSelected = string.Equals(value, "true", StringComparison.OrdinalIgnoreCase);
                <li id="@feature.Name" class="jstree-open" data-jstree='{"selected": @isSelected.ToString().ToLower()}' data-feature='@feature.ToJsonString(true)' data-feature-value='@value.Replace("'","''")'>
                    @feature.DisplayName 
                    @Html.Partial("~/Areas/Admin/Views/Common/_FeaturesTreeItem.cshtml", new FeatureTreeItemModel(Model.EditModel, feature.Name))
                </li>
            }
        </ul>
    }
}